@extends('Admin.Index.index')
@section('后台管理系统Ace','商品控制')
@section('admin.model')
<script src="{{URL::asset('Admin/assets/js/jquery.min.js')}}"></script>
<!-- <form action="">
	<div class="form-actions">
		<div class="input-group">
			<input placeholder="搜索 ..." type="text" class="form-control" name="message" />
			<span class="input-group-btn">
				<button class="btn btn-sm btn-info no-radius" type="button">
					<i class="icon-share-alt"></i>
					点击搜索
				</button>
			</span>
		</div>
	</div>
</form> -->
<form action="/admin/goodsSelect" method="post" enctype="multipart/form-data">
	{!!csrf_field()!!}
		<input type="text" name="gname" id="" placeholder="商品名" style="width:250px" class="input-text">
		<button type="submit" name="" id="" class="btn btn-sm btn-info no-radius">搜索</button>
</form>
<table id="sample-table-2" class="table table-striped table-bordered table-hover">
	<thead>
		<tr>
			<th class="center">
				商品ID
			</th>
			<th>商品名</th>
			<th>价格</th>
			<th class="hidden-480">分类</th>

			<th>
				<i class="icon-time bigger-110 hidden-480"></i>
				更新时间
			</th>
			<th class="hidden-480">商品图片</th>

			<th></th>
		</tr>
	</thead>
	<h4>商品列表</h4>
	@foreach($result as $key)
	<tbody>
		<tr>
			<td class="center">
				{{$key->gid}}
			</td>
			<td>
				<a href="#">{{$key->gname}}</a>
			</td>
			<td>{{$key->gprice}}</td>
			<td class="hidden-480">{{$key->cname}}</td>
			<td>{{date("Y-m-d",time())}}</td> <!--H:i:s-->

			<td class="hidden-480">
				<img style="height:50px" src="/uploads/{{$key->gimg}}"/>
			</td>

			<td>
				<div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
					<a class="blue" href="/admin/goodsadd/{{$key->gid}}">
						下架&nbsp<i class="icon-zoom-in bigger-130"></i>
					</a>

					<a class="green" href="/admin/goodsupdate/{{$key->gid}}">
						修改&nbsp<i class="icon-pencil bigger-130"></i>
					</a>

					<a class="del" id="{{$key->gid}}" href="javascript:void(0);">
						删除&nbsp<i class="icon-trash bigger-130"></i>
					</a>
				</div>

				<div class="visible-xs visible-sm hidden-md hidden-lg">
					<div class="inline position-relative">
						<button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
							<i class="icon-caret-down icon-only bigger-120"></i>
						</button>

						<ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">
							<li>
								<a href="#" class="tooltip-info" data-rel="tooltip" title="View">
									<span class="blue">
										<i class="icon-zoom-in bigger-120"></i>
									</span>
								</a>
							</li>

							<li>
								<a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
									<span class="green">
										<i class="icon-edit bigger-120"></i>
									</span>
								</a>
							</li>

							<li>
								<a href="#" class="tooltip-error" data-rel="tooltip" title="Delete">
									<span class="red">
										<i class="icon-trash bigger-120"></i>
									</span>
								</a>
							</li>
						</ul>
					</div>
				</div>
			</td>
		</tr>
	</tbody>
	@endforeach
	<tr>
		<td colspan="5">{!! $result->render() !!}</td>
	</tr>
	<script type="text/javascript">
		$(function(){
			$('.del').click(function(){

				//获取当前操作的商品ID
				var gid = $(this).attr('id');
				//确定操作
				if(!confirm('您确定删除ID为'+gid+'的商品吗')){
					return false;
				}
				//ajax操作
				$.ajax({
					url:'/admin/goodsdelete/'+gid,
					type:'get',
					dataType:'text',
					success:function(data){
						//根据返回数据操作
						if(data==1){
							//删除数据
							$('#'+gid).parent().parent().parent().remove();
						}else{
							alert('删除商品失败');
						}
					}
				})
			});
			// var gid = $(this).attr('id');

			// $.ajax({
			// 	url: '/admin/goodsdelete/'+gid,//1602
			// 	type: 'GET',
			// 	dataType: 'text',
			// 	success:function(){
			// 		alert('xxx');
			// 	}
			// })
		})
	</script>
</table>
@endsection